package com.yida.wy.vote.outside.controller;

import com.yida.common.core.constant.SecurityConstants;
import com.yida.common.core.domain.R;
import com.yida.common.core.utils.CheckRemoteServiceResultUtils;
import com.yida.common.core.utils.StringUtils;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.wy.vote.outside.enums.WyDictTypeEnum;
import com.yida.system.api.RemoteDictDataService;
import com.yida.system.api.domain.SysDictData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 投票字典Controller
 *
 * @author lqq
 * @date 2023-05-08
 */
@RestController
@RequestMapping("/dict/data")
@Api(tags = "投票字典")
public class WyDictDataController extends BaseController {

	@Resource
	private RemoteDictDataService remoteDictDataService;

	@ApiOperation("根据字典类型查询字典数据信息")
	@PostMapping("/type/{dictType}")
	public AjaxResult dictType(@PathVariable String dictType) {
		if (StringUtils.isNull(WyDictTypeEnum.getByCode(dictType))) {
			AjaxResult.success(new ArrayList<SysDictData>());
		}
		R<List<SysDictData>> r = remoteDictDataService.dictType(dictType, SecurityConstants.INNER);
		return AjaxResult.success(CheckRemoteServiceResultUtils.isSuccessWithData(r) ? r.getData() : new ArrayList<SysDictData>());
	}
}
